package com.ayf.payment.game.api.channel.xingyou.util;

import com.ayf.payment.game.api.utils.MD5Util;
import com.swwx.charm.commons.lang.utils.LogPortal;
import org.apache.commons.lang.StringUtils;

import java.util.Map;

public final class XingYou2SignUtil {

    public static String getSign(String traceId,String methodName,Map<String,String> reqParam,String key) {
        StringBuffer reqStr = new StringBuffer();
        for (Map.Entry<String, String> entry : reqParam.entrySet()){
            String paramKey = entry.getKey();
            String paramValue = entry.getValue();
            reqStr.append(paramKey).append("=").append(paramValue).append("&");
        }
        String signOriginStr =reqStr.toString().concat("key=").concat(key);
        LogPortal.debug("{} {} 签名原文:{}",traceId,methodName,signOriginStr);
        String sign = MD5Util.strToMd5Utf8(signOriginStr);
        if (StringUtils.isEmpty(sign)) {
            return null;
        }
        sign = sign.toUpperCase();
        LogPortal.debug("{} {} 实际签名:{}",traceId,methodName,sign);
        return sign;
    }

}
